<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/7
 * Time: 13:41
 */

namespace App\Services;
use App\Models\WechatQrcode;
use App\Models\WechatRequest;
use Log;
use EasyWeChat\Support\Collection;
use EasyWeChat\Foundation\Application as EasyWeChat;
use EasyWeChat\Message\Image as MessageImage;
use EasyWeChat\Message\Text;


class WechatTextService
{
    public $wechatRequestModel;
    public $wechatQrcodeModel;
    public $easyWechat;

    public function __construct(WechatRequest $wechatRequest,WechatQrcode $wechatQrcode, EasyWeChat $easyWechat)
    {
        $this->wechatRequestModel = $wechatRequest;
        $this->easyWechat = $easyWechat;
        $this->wechatQrcodeModel = $wechatQrcode;
    }

    public function handle(Collection $message){
        $this->wechatRequestModel->create($message->toArray());
        $this->fromUser = $this->easyWechat->user->get($message->FromUserName);
        $wechatQrcode = $this->wechatQrcodeModel->where("scene_name",$message->Content)->first();
        if($wechatQrcode){
            return new MessageImage(['media_id' => $wechatQrcode->qrcode_media_id]);
        }else {
            return new \EasyWeChat\Message\Transfer();
            //return null;
        }
    }

}